package thread_test;

public class ThreadDemo10 {
    public static long num1 = 0;
    public static long num2 = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 5_000_00; i++) {
                num1 += i;
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 5_000_00; i <= 1_000_000; i++) {
                num2 += i;
            }
        });
        t1.start();
        t2.start();
        // 等待 t1 执行结束
        t1.join();
        // 等待 t2 执行结束
        t2.join();
        long sum = num1 + num2;
        System.out.println("num1 + num2 = " + sum);
    }
}